package com.woniu.cms.goods.core.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.woniu.cms.goods.core.entity.GoodsDictionary;
import com.woniu.cms.goods.core.entity.GoodsStores;
import com.woniu.cms.goods.core.entity.GoodsSupplier;
import com.woniu.cms.goods.core.service.IGoodsSupplierService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 物资供应商表 前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-17
 */
@RestController
@Api(tags = "物资供应商模块")
@RequestMapping("/goods-supplier")
public class GoodsSupplierController {

    @Autowired
    private IGoodsSupplierService supplierService;

    /*
     * 物资供应商分页查询方法
     * @currentPage 当前页码
     * @pageSize 页面大小
     * @storeName 用户输入的仓库名称
     * */
    @GetMapping("list")
    @ApiOperation("分页查询/以供应商名称模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
            @ApiImplicitParam(name = "storeName",value = "供应商名称")
    })
    public Result getList(Integer currentPage, Integer pageSize,String supplierName,Integer status){
        Result result = supplierService.getlist(currentPage,pageSize,supplierName,status);
        return result;
    }
    /*
     * 新增物资供应商的方法
     * @stores 用户输入的供应商对象的
     * */
    @PutMapping("insert")
    @ApiOperation("新增供应商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stores",value = "添加供应商对象")
    })
    public Result addStore(@RequestBody GoodsSupplier goodsSupplier) throws JsonProcessingException {
        Result result= supplierService.addSupplier(goodsSupplier);
        return result;
    }
    /*
     * 删除供应商的方法，只能删除未提交或已驳回的单子。当供应商有被1条或多条合同引用时无法删除
     * @id 供应商id
     * */
    @DeleteMapping("delete/{id}")
    @ApiOperation("删除供应商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "需删除的供应商id")
    })
    public Result deleteStore(@PathVariable("id") Integer id){
        Result result=supplierService.deleteSupplier(id);
        return result;
    }
    /*
     * 修改供应商的方法，只能修改未提交、已驳回的单子。当供应商有被1条或多条合同引用时无法删除
     * @goodsSupplier 修改的供应商对象
     * */
    @PutMapping("update")
    @ApiOperation("修改供应商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsSupplier",value = "修改的对象")
    })
    public Result updateDictionary(GoodsSupplier goodsSupplier){
        Result result = supplierService.updateSupplier(goodsSupplier);
        return result;
    }
}

